﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommerceOne.Common;
using CommerceOne.Domains.Commons;
using CommerceOne.Domains.IRepositories;
using CommerceOne.Domains.Services;
using CommerceOne.Domains.SqlRepositories;
using CommerceOne.Models;
using CommerceOne.Models.Entities;
using CommerceOne.Widgets.CheckoutStep;
using CommerceOne.Widgets.HeroImage;
using CommerceOne.Widgets.NewestProducts;
using Configurations = CommerceOne.Widgets.HeroImage.Configurations;


namespace CommerceOne.Controllers
{
    public class HomeController : ControllerBase
    {
        private readonly IProductRepository _productRepository = SqlProductRepository.Instance;
        private readonly IProductPhotoRepository _productPhotoRepository = SqlProductPhotoRepository.Instance;

        /// <summary>
        /// Indexes the specified page number.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var viewModel = new HomeViewModel();

            var newestProductController = new NewestProductController {HttpContextBase = this.HttpContext};
            viewModel.NewestProductList = newestProductController.GetViewModel();

            this.CommonInitialize(viewModel, new Parameters{ ObjectId = 0});


            //var item = new Widgets.CheckoutStep.Configurations
            //               {
            //                   Steps = new List<Step>()
            //                               {
            //                                   new Step() {Index = 1, Name = "Summary", PageType = PageType.Cart},
            //                                   new Step() {Index = 2, Name = "Login", PageType = PageType.Login},
            //                                   new Step() {Index = 3, Name = "Address ", PageType = PageType.Address},
            //                                   new Step() {Index = 4, Name = "Shipping", PageType = PageType.Shipping},
            //                                   new Step() {Index = 5, Name = "Payment", PageType = PageType.Payment},
            //                               }
            //               };

            //Item.MaximumProductName = 30;
            //Item.NumberOfProduct = 6;

            //SerializeService.Instance.SerializeObject<Widgets.CheckoutStep.Configurations>(HttpContext.Server.MapPath("Configurations/CheckoutStep.xml"), item);

            //int size = 10;
            //int totalRecord = this._productRepository.GetTotalItem();

            //PagingSortingNavController pagingSortingController = new PagingSortingNavController();
            //viewModel.PagingSortingViewModel = pagingSortingController.GetViewModel(totalRecord, size, 1, "/{0}");
            
            ////int skip = (pageNumber - 1) * size;
            //viewModel.NewestProductList = this._productRepository.GetAll().OrderBy(p=>p.AvailableDay).Take(size).ToList();

            ////IFilterParam brandParam = new FilterParam<int>("ProductSearchView", "BrandId", FilterType.Equal, 6);
            ////IFilterParam categoryParam = new FilterParam<int>("ProductSearchView", "CategoryId", FilterType.Equal, 1);
            ////List<IFilterParam> filterList = new List<IFilterParam>(new IFilterParam[] { brandParam, categoryParam });

            ////ISearchService searchService = new SearchService();
            ////SearchProductResult searchResult = searchService.SearchProduct(string.Empty, filterList););)););)
            
            return View(viewModel);
        }

        public ActionResult Test()
        {
            var viewModel = new TestViewModel();
            this.CommonInitialize(viewModel, new Parameters { ObjectId = 0 });
            viewModel.Day = DateTime.Today;
            return View(viewModel);
        }

    }
}
